﻿#region using declarations

using DPSF;
using Microsoft.Xna.Framework;
using NGen.Managers.Logging;

#endregion

namespace NGen.Managers.Particles {
	public class ManagerParticles : ParticleSystemManager, IManagerParticles {
		#region IGameManager implementation

		/// <summary>
		/// 	get or set if this manager should skip its _Update call
		/// </summary>
		public bool SkipUpdate {
			get { return !Enabled; }
			set { Enabled = !value; }
		}

		/// <summary>
		/// 	get or set if this manager should skip its Draw call
		/// </summary>
		public bool SkipDraw {
			get { return !Visible; }
			set { Visible = !value; }
		}

		/// <summary>
		/// 	get or set this managers' logging level
		/// </summary>
		public LoggingLevel CurrentLoggingLevel { get; set; }

		///<summary>
		///	get the logger used to log messages
		///</summary>
		public ILogger Logger { get; set; }

		/// <summary>
		/// 	initialize this manager
		/// </summary>
		public void _Initialize() {
			CurrentLoggingLevel = LoggingLevel.MINIMAL;
			Logger = GameEngine.GetService<IManagerLogs>().Log<ManagerParticles>();
			SkipUpdate = false;
			SkipDraw = false;
		}

		/// <summary>
		/// 	update this manager
		/// </summary>
		/// <param name = "p_gameTime">snapshot of timing values</param>
		public void _Update(GameTime p_gameTime) {
			UpdateAllParticleSystemsForced((float)p_gameTime.ElapsedGameTime.TotalSeconds);
		}

		/// <summary>
		/// 	draw this manager
		/// </summary>
		/// <param name = "p_gameTime">snapshot of timing values</param>
		public void _Draw(GameTime p_gameTime) {
			DrawAllParticleSystemsForced();
		}

		/// <summary>
		/// 	cleanup this manager
		/// </summary>
		public void _Cleanup() {
			DestroyAndRemoveAllParticleSystems();
		}

		#endregion

		#region IManagerParticles implementation

		/// <summary>
		/// 	get or set the default number of particles to initially allocate memory for, per system
		/// </summary>
		public int DefaultInitialParticleAllocationCountPerSystem { get; set; }

		/// <summary>
		/// 	get or set the default maximum number of particles per system
		/// </summary>
		public int DefaultMaximumParticlesPerSystem { get; set; }

		public new void AddParticleSystem(IDPSFParticleSystem p_system) {
			base.AddParticleSystem(p_system);
			p_system.AutoInitialize(GameEngine.GraphicsDevice, GameEngine.GameContent, GameEngine.SpriteBatch);
		}

		public new void RemoveParticleSystem(IDPSFParticleSystem p_system) {
			base.RemoveParticleSystem(p_system);
			p_system.Destroy();
		}

		#endregion
	}
}